
use gfsc::*;
use ansi_term::Colour;

pub fn main() {
    if std::env::args().len() < 3 {
        println!("{} file_name where_is_router.json", std::env::args().nth(0).unwrap_or_default());
        return
    }
    let pattern = std::env::args().nth(1).expect("no pattern given");    
    let conf = std::env::args().nth(2).expect("no router.json given");
    let router = gfsc_new_router( conf.as_str() ).unwrap();    
    // let ihash = gfs_filename_hash(filename.as_str());    
    //     let reader = router.get_reader(router.cur_dynasty, ihash).unwrap();        
    let f = gfsc_grep_file(&router , router.cur_dynasty, pattern.as_str());
    let rt = tokio::runtime::Runtime::new().unwrap();
    let r = rt.block_on(f).unwrap();
    // println!("{:#?}", r);
    for i in 0..r.len() {       
        let doc = &r[i];
        let s = &doc.content;
        let nc = s.replace("<mark>" , Colour::Red.prefix().to_string().as_str());
        let nc =  nc.replace("</mark>" , Colour::Red.suffix().to_string().as_str());
        println!("{} : {}", doc.fname, nc);
    }
    
}
 